package com.java.control.search;

import org.apache.commons.lang.StringUtils;

import com.java.mis.UserType;

/**
 * 人员
 * @author wqf
 * @version  Nov 24, 2011 11:55:45 AM
 */
public class UserSearchCond extends SearchCond{
	
	private String userName;
	private String account;
	private String code;
	private Boolean sex;
	private Boolean isAdmin;
	private Boolean status;
	private Long userId;

	public Long getUserId() {
		return userId;
	}


	public void setUserId(Long userId) {
		this.userId = userId;
	}


	public Boolean getStatus() {
		return status;
	}


	public void setStatus(Boolean status) {
		this.status = status;
	}


	public String getAccount() {
		return account;
	}


	public void setAccount(String account) {
		this.account = account;
	}


	public String getCode() {
		return code;
	}


	public void setCode(String code) {
		this.code = code;
	}


	public Boolean getSex() {
		return sex;
	}


	public void setSex(Boolean sex) {
		this.sex = sex;
	}


	public ConditionPart getCondition(){
		ConditionPart cp=new ConditionPart();
		StringBuffer searchStr=new StringBuffer(" 1=1");
		
		if(null!=status){
			searchStr.append(" and status=?");
			cp.getParams().add(status);
		}
		if(null!=isAdmin){
			if(isAdmin){
				searchStr.append(" and userType=?");
				cp.getParams().add(UserType.admin);
			}else{
				searchStr.append(" and userType!=?");
				cp.getParams().add(UserType.admin);
			}
		}
		if(null!=userId){
			searchStr.append(" and id=?");
			cp.getParams().add(userId);
		}
		if(null!=sex){
			searchStr.append(" and sex=?");
			cp.getParams().add(sex);
		}
		if(StringUtils.isNotBlank(code)){
			searchStr.append(" and code=?");
			cp.getParams().add(code);
		}
		if(StringUtils.isNotBlank(account)){
			searchStr.append(" and account like ?");
			cp.getParams().add("%"+account.trim()+"%");
		}
		if(StringUtils.isNotBlank(userName)){
			searchStr.append(" and userName like ?");
			cp.getParams().add("%"+userName.trim()+"%");
		}
		
		cp.setExpression(searchStr.toString());
		return cp;
	}


	public Boolean getIsAdmin() {
		return isAdmin;
	}


	public void setIsAdmin(Boolean isAdmin) {
		this.isAdmin = isAdmin;
	}


	public String getUserName() {
		return userName;
	}


	public void setUserName(String userName) {
		this.userName = userName;
	}

}
